// ----------------------------------
// RSDK Project: Sonic Pocket Reventure
// Script Description: NSZ Setup Object
// Script Author: Christan Whitehead/Simon Thomley/Tails LP
// ----------------------------------

//-------Aliases-------//
private alias 39 : TYPE_TESTSETUP
private alias saveRAM[399] : spindash.active	//63C SData.bin
private alias saveRAM[400] : peelout.active	//640 SData.bin
private alias saveRAM[401] : dropdash.active	//644 SData.bin
private alias saveRAM[402] : shilds.type	//648 SData.bin
private alias saveRAM[403] : music.type		//64C SData.bin
private alias saveRAM[404] : timer.type		//650 SData.bin
private alias saveRAM[405] : timeover.active	//654 SData.bin
private alias saveRAM[406] : flight.cancel	//658 SData.bin
private alias saveRAM[407] : region.type	//65C SData.bin
private alias saveRAM[408] : lives.amount	//660 SData.bin
private alias saveRAM[409] : tiger.active	//664 SData.bin


// Function declarations
reserve function NSZSetup_Function93
reserve function NSZSetup_Function94

// Static Values
public value ZoneSetup_value33 = 0;
public value NSZSetup_value29 = 0;
public value NSZSetup_value30 = 0;
public value NSZSetup_value31 = 0;

// Tables

public table NSZSetup_table0
	0x500000, 0x3B00000, 0, 11, 8, 91, 56, 1, 40, 7, 8, 87, 56, 1, 40, 8, 8, 47, 56, 1, 40, 7, 8, 204, 56, 1, 40, 7, 8, 32, 56, 1, 40, 9, 8, 43, 56, 1, 40, 28, 8, 61, 56, 1, 40, 24, 8, 30, 56, 1, 40, 44, 8, 22, 56, 1, 40, 21, 8, 42, 56, 1, 40, 107, 8, 255, 8, 33, 0, 203, 4, 44, 0, 12, 4, 11, 0, 23, 8, 20, 0, 15, 4, 4, 0, 19, 8, 16, 56, 1, 40, 10, 8, 39, 56, 1, 40, 8, 8, 42, 56, 1
end table

public table NSZSetup_table1
	0x500000, 0x3B40000, 0, 11, 8, 91, 56, 1, 40, 10, 8, 75, 4, 12, 52, 1, 36, 24, 4, 19, 52, 1, 36, 7, 4, 8, 0, 27, 8, 55, 56, 1, 40, 4, 32, 5, 0, 29, 4, 25, 0, 11, 8, 34, 0, 11, 8, 30, 56, 1, 40, 9, 8, 202, 56, 1, 40, 9, 8, 35, 56, 1, 40, 8, 8, 45, 56, 1, 40, 14, 8, 17, 0, 7, 8, 52, 56, 1, 40, 17, 8, 33, 56, 1, 40, 33, 8, 2, 0, 29, 8, 14, 56, 1, 40, 6, 8, 5, 0, 13, 4, 9, 0, 11, 48, 1, 32, 6, 8, 6, 56, 1, 40, 6, 8, 16, 56, 1, 40, 5, 8, 33, 0, 8, 4, 11, 0, 21, 8, 9, 0, 31, 48, 1, 32, 6, 0, 2, 8, 28, 0, 28, 4, 5, 0, 5, 8, 25, 56, 1, 40, 2, 8, 28, 0, 6, 4, 9, 0, 6, 8, 31, 0, 45, 56, 1, 40, 5, 0, 2, 8, 9, 0, 7, 8, 10, 0, 30, 8, 12, 0, 37, 4, 17, 0, 22, 8, 20, 56, 1, 40, 11, 8, 52, 56, 1, 40, 12
end table

public table NSZSetup_table2
	0x500000, 0x3B00000, 0, 11, 8, 92, 56, 1, 40, 12, 8, 82, 2, 12, 0, 24, 48, 1, 32, 26, 0, 3, 8, 2, 56, 1, 40, 88, 8, 2, 0, 28, 2, 16, 50, 1, 34, 7, 2, 5, 50, 1, 34, 2, 2, 5, 50, 1, 34, 3, 2, 3, 50, 1, 34, 2, 2, 4, 8, 105, 0, 109, 8, 12, 56, 1, 40, 44, 8, 51, 56, 1, 40, 33, 8, 17, 56, 1, 40, 40, 8, 31, 56, 1, 40, 39, 8, 24, 56, 1, 40, 64, 8, 17, 56, 1, 40, 15, 8, 241, 0, 29, 48, 1, 32, 18, 0, 4, 48, 1, 32, 30, 33, 3, 1, 171, 0, 15, 2, 12, 50, 1, 34, 7, 2, 4, 50, 1, 34, 2, 2, 6, 50, 1, 34, 2, 2, 4, 50, 1, 34, 5, 2, 22, 0, 2, 8, 47, 0, 6
end table

public table NSZSetup_table3
	0x500000, 0x3B00000, 8, 91, 56, 1, 40, 9, 8, 83, 56, 1, 40, 5, 8, 52, 56, 1, 40, 8, 8, 160, 0, 8, 8, 26, 56, 1, 40, 3, 32, 2, 0, 6, 4, 5, 0, 13, 8, 44, 56, 1, 40, 5, 8, 17, 0, 16, 8, 13, 8, 5, 8, 42, 0, 52, 8, 30
end table

public table NSZSetup_table4
	0x13E80000, 0x2AC0000, 0, 17, 8, 255, 8, 31, 0, 219
end table

public table NSZSetup_Deform
	1, 2, 1, 3, 1, 2, 2, 1, 2, 3, 1, 2, 1, 2, 0, 0
	2, 0, 3, 2, 2, 3, 2, 2, 1, 3, 0, 0, 1, 0, 1, 3
	1, 2, 1, 3, 1, 2, 2, 1, 2, 3, 1, 2, 1, 2, 0, 0
	2, 0, 3, 2, 2, 3, 2, 2, 1, 3, 0, 0, 1, 0, 1, 3
end table

function NSZSetup_Function93
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("SPEED.ogg", 0, 0x7AA16, 1)
			break
		case 2
			SetMusicTrack("SPEED.ogg", 0, 1)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		case 4
			SetMusicTrack("SPEED.ogg", 0, 1)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function NSZSetup_Function94
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("SSPLASH.ogg", 0, 1, 1)
			break
		case 2
			SetMusicTrack("SSPLASH.ogg", 0, 1)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		case 4
			SetMusicTrack("SSPLASH.ogg", 0, 1)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


event ObjectMain
	if NSZSetup_value30 != 0
		NSZSetup_value30 = 0
		object.value4--
		if object.value4 <= 0
			object.value4 = 31
			if object.value5 == 0
				if credits.screen == 0
					PlaySfx(SfxName[Waterfall], 0)
					StopSfx(SfxName[Waterfall Loop])
				end if
				object.value5 = 1
			else
				if credits.screen == 0
					StopSfx(SfxName[Waterfall])
					PlaySfx(SfxName[Waterfall Loop], 0)
				end if
			end if
		end if
		SetSfxAttributes(SfxName[Waterfall], -1, NSZSetup_value31)
		SetSfxAttributes(SfxName[Waterfall Loop], -1, NSZSetup_value31)
	else
		object.value5 = 0
		object.value4 = 0
	end if
	if object.state < 5
		object.value3++
		if object.value3 == 6
			object.value3 = 0
			RotatePalette(0, 188, 191, 0)
			NSZSetup_value29++
			NSZSetup_value29 &= 15
		end if
	end if

end event


event ObjectStartup
	if tiger.active == 1
		LoadPalette("Tiger/NSI.act", 0, 0, 0, 255)
	endif
	arrayPos0 = 0
	while arrayPos0 < 576
		temp0 = arrayPos0
		temp0 &= 63
		GetTableValue(stage[arrayPos0].deformationData2, temp0, NSZSetup_Deform)
		arrayPos0++
	loop
	SetMusicTrack("SSPLASH.ogg", 0, 1)
	SpeedUpMusic = NSZSetup_Function93
	SlowDownMusic = NSZSetup_Function94
	animalType1 = TypeName[Pocky]
	animalType2 = TypeName[Flicky]
	//Abs(tileLayer[1].parallaxFactor)
	//FlipSign(tileLayer[1].parallaxFactor)
	//tileLayer[1].scrollPos = 0x180000
	object[10].type = TypeName[NSZ Setup]
	object[10].priority = PRIORITY_ACTIVE
	NSZSetup_value29 = 0
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
